{include file="public/_header" /}
<div class="x-body">
    <form class="layui-form" method="post" enctype="multipart/form-data" action="/admin/agent/add_save">

        <div class="layui-form-item">
            <label  class="layui-form-label">
                <span class="x-red">*</span>代理账户名
            </label>
            <div class="layui-input-inline">
                <input type="text" name="user_name" required="" lay-verify="required"
                       autocomplete="off" class="layui-input">
            </div>
        </div>


        <div class="layui-form-item">
            <label  class="layui-form-label">
                <span class="x-red">*</span>代理账户密码
            </label>
            <div class="layui-input-inline">
                <input type="text" name="password" id="pwd" required="" lay-verify="required"
                       autocomplete="off" class="layui-input">
            </div>
        </div>


        <div class="layui-form-item">
            <label  class="layui-form-label">
                <span class="x-red">*</span>公司名称
            </label>
            <div class="layui-input-inline">
                <input type="text" name="company_name" required="" lay-verify="required"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label  class="layui-form-label">
                <span class="x-red">*</span>身份证号码
            </label>
            <div class="layui-input-inline">
                <input type="text" name="id_card_num" id="idcard1" required="" lay-verify="required"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label  class="layui-form-label">
                <span class="x-red">*</span>电话
            </label>
            <div class="layui-input-inline">
                <input type="text" name="mobile" id="tel1" required="" lay-verify="required"
                       autocomplete="off" class="layui-input">
            </div>
        </div>



        <div class="layui-form">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">代理起止时间</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" id="test10" placeholder="-" name="agent_time_str" required="" lay-verify="required">
                    </div>
                </div>
            </div>
        </div>


        <div class="layui-form-item">
            <label  class="layui-form-label">
                <span class="x-red">*</span>有效联系人
            </label>
            <div class="layui-input-inline">
                <input type="text" name="linkman" required="" lay-verify="required"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label  class="layui-form-label">
                <span class="x-red">*</span>有效联系人电话
            </label>
            <div class="layui-input-inline">
                <input type="text" name="linkman_mobile" id="tel2" required="" lay-verify="required"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label  class="layui-form-label">
                <span class="x-red">*</span>担保人姓名
            </label>
            <div class="layui-input-inline">
                <input type="text" name="secure_name" required="" lay-verify="required"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label  class="layui-form-label">
                <span class="x-red">*</span>担保人身份证号码
            </label>
            <div class="layui-input-inline">
                <input type="text" name="secure_id_card_num"  id="idcard2" required="" lay-verify="required"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label  class="layui-form-label">
                <span class="x-red">*</span>担保人电话号
            </label>
            <div class="layui-input-inline">
                <input type="text" name="secure_mobile" id="tel3" required="" lay-verify="required"
                       autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label  class="layui-form-label">
                <span class="x-red">*</span>关系
            </label>
            <div class="layui-input-inline">
                <input type="text" name="secure_relation" required="" lay-verify="required"
                       autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label  class="layui-form-label">
                <span class="x-red">*</span>是否启用
            </label>
            <div class="layui-input-inline">
                <input type="radio" name="status" value="1" title="启用" checked>
                <input type="radio" name="status" value="0" title="禁用">
            </div>
        </div>



        <div class="layui-form-item">
            <label  class="layui-form-label">
                <span class="x-red"></span><!--省份-->
            </label>
            <div class="layui-input-inline">
                <input type="hidden" name="province" required="" id="province"  value="{$province}" lay-verify="required"
                       autocomplete="off" class="layui-input" readonly>
          <!--  <select lay-filter="provinceId" id="province" name="province" class="provinceid">
                <option value="">省份</option>
                {volist name='province' id='pro'}
                <option value="{$pro.provinceid}">{$pro.province}</option>
                {/volist}
            </select>-->
        </div>
        </div>

        <div class="layui-form-item">
            <label  class="layui-form-label">
                <span class="x-red"></span><!--城市-->
            </label>
            <div class="layui-input-inline">
                <div class="layui-input-inline">
                    <input type="hidden" name="city" required="" id="city"  value="{$city}" lay-verify="required"
                           autocomplete="off" class="layui-input" readonly>
        </div>
        </div>





        <div class="layui-form-item">
            <label class="layui-form-label">代理商手持身份证</label>
            <div class="layui-upload">
                <button type="button" class="layui-btn" id="test1">上传图片</button>
                <div class="layui-upload-list">
                    <img class="layui-upload-img" id="demo1">
                    <p id="demoText"></p>
                </div>
            </div>
            <input type="hidden" name="hand_id_card" id="upload_imgs">
        </div>


        <div class="layui-form-item">
            <label class="layui-form-label">代理商身份证正面</label>
            <div class="layui-upload">
                <button type="button" class="layui-btn" id="test2">上传图片</button>
                <div class="layui-upload-list">
                    <img class="layui-upload-img" id="demo2">
                    <p id="demoText2"></p>
                </div>
            </div>
            <input type="hidden" name="front_id_card" id="upload_imgs2">
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">代理商身份证反面</label>
        <div class="layui-upload">
            <button type="button" class="layui-btn" id="test3">上传图片</button>
            <div class="layui-upload-list">
                <img class="layui-upload-img" id="demo3">
                <p id="demoText3"></p>
            </div>
        </div>
        <input type="hidden" name="backend_id_card" id="upload_imgs3">
        </div>


        <div class="layui-form-item">
            <label class="layui-form-label">担保人手持身份证</label>
            <div class="layui-upload">
                <button type="button" class="layui-btn" id="test4">上传图片</button>
                <div class="layui-upload-list">
                    <img class="layui-upload-img" id="demo4">
                    <p id="demoText4"></p>
                </div>
            </div>
            <input type="hidden" name="secure_hand_id_card" id="upload_imgs4">
        </div>


        <div class="layui-form-item">
            <label class="layui-form-label">担保人身份证正面</label>
            <div class="layui-upload">
                <button type="button" class="layui-btn" id="test5">上传图片</button>
                <div class="layui-upload-list">
                    <img class="layui-upload-img" id="demo5">
                    <p id="demoText5"></p>
                </div>
            </div>
            <input type="hidden" name="secure_front_id_card" id="upload_imgs5">
        </div>


        <div class="layui-form-item">
            <label class="layui-form-label">担保人身份证反面</label>
            <div class="layui-upload">
                <button type="button" class="layui-btn" id="test6">上传图片</button>
                <div class="layui-upload-list">
                    <img class="layui-upload-img" id="demo6">
                    <p id="demoText6"></p>
                </div>
            </div>
            <input type="hidden" name="secure_backend_id_card" id="upload_imgs6">
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">公司营业执照</label>
            <div class="layui-upload">
                <button type="button" class="layui-btn" id="test7">上传图片</button>
                <div class="layui-upload-list">
                    <img class="layui-upload-img" id="demo7">
                    <p id="demoText7"></p>
                </div>
            </div>
            <input type="hidden" name="business_license_img" id="upload_imgs7">
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn"  lay-submit="" lay-filter="formDemo">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>


    </form>
</div>
{include file="public/_footer" /}
<script>
    layui.use(['form', 'layer'], function () {
        $ = layui.jquery;
        var form = layui.form
                , layer = layui.layer;

        //自定义验证规则
        form.verify({
            nikename: function (value) {
                if (value.length < 5) {
                    return '昵称至少得5个字符啊';
                }
            }
            , pass: [/(.+){6,12}$/, '密码必须6到12位']
            , repass: function (value) {
                if ($('#L_pass').val() != $('#L_repass').val()) {
                    return '两次密码不一致';
                }
            }
        });

        //监听提交
        form.on('submit(add)', function (data) {
            console.log(data);
            //发异步，把数据提交给php
            layer.alert("增加成功", {icon: 6}, function () {
                // 获得frame索引
                var index = parent.layer.getFrameIndex(window.name);
                //关闭当前frame
                parent.layer.close(index);
            });
            return false;
        });


    });

    layui.use('laydate', function () {
        $ = layui.jquery;
        var laydate = layui.laydate;
        //日期时间范围
        laydate.render({
            elem: '#test10'
            , type: 'datetime'
            , range: true
        });
    });

    layui.use('upload', function () {
        var $ = layui.jquery
                , upload = layui.upload;
        var data = [{
            btnEl: "#test1",
            imgEl: "#demo1",
            uploadShowEl: "upload_imgs",
            errEl: "#demoText"
        }, {
            btnEl: "#test2",
            imgEl: "#demo2",
            uploadShowEl: "upload_imgs2",
            errEl: "#demoText2"
        }, {
            btnEl: "#test3",
            imgEl: "#demo3",
            uploadShowEl: "upload_imgs3",
            errEl: "#demoText3"
        }, {
            btnEl: "#test4",
            imgEl: "#demo4",
            uploadShowEl: "upload_imgs4",
            errEl: "#demoText4"
        }, {
            btnEl: "#test5",
            imgEl: "#demo5",
            uploadShowEl: "upload_imgs5",
            errEl: "#demoText5"
        }, {
            btnEl: "#test6",
            imgEl: "#demo6",
            uploadShowEl: "upload_imgs6",
            errEl: "#demoText6"
        }, {
            btnEl: "#test7",
            imgEl: "#demo7",
            uploadShowEl: "upload_imgs7",
            errEl: "#demoText7"
        }];
        for(var i in data){
            uploadFile({
                btnEl:data[i].btnEl,
                imgEl:data[i].imgEl,
                uploadShowEl:data[i].uploadShowEl,
                errEl:data[i].errEl
            })
        }

        function uploadFile(option) {
            //普通图片上传
            var uploadInst = upload.render({
                        elem: option.btnEl//按钮el
                    , url: '/api/upload/uploadFile'
                    , before: function (obj) {
                //预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result) {
                    $(option.imgEl).attr('src', result); //图片链接（base64）查看显示图片节点id imgEl
                });
            }
        , done: function (res) {
                //如果上传失败
                if (res.code > 0) {
                    return layer.msg('上传失败');
                }
                if (res.code == 0) {
                    //do something （比如将res返回的图片链接保存到表单的隐藏域）
                    document.getElementById(option.uploadShowEl).value = res.data.src;    //uploadShowEl 上传成功显示图片节点id
                }
                console.log(res)
                //上传成功
            }
        , error: function () {
                //演示失败状态，并实现重传
                var demoText = $(option.errEl);  //errEl    上传失败上传显示地址
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function () {
                    uploadInst.upload();
                });
            }
        });
        }



//        function uplosd(option) {
//            upload.render({
//                elem: '#test1'
//                , url: '/api/upload/uploadFile'
//                , before: function (obj) {
//                    //预读本地文件示例，不支持ie8
//                    obj.preview(function (index, file, result) {
//                        $('#demo1').attr('src', result); //图片链接（base64）
//                    });
//                }
//                , done: function (res) {
//                    //如果上传失败
//                    if (res.code > 0) {
//                        return layer.msg('上传失败');
//                    }
//                    if (res.code == 0) {
//                        //do something （比如将res返回的图片链接保存到表单的隐藏域）
//                        document.getElementById('upload_imgs').value = res.data.src;
//                    }
//                    console.log(res)
//                    //上传成功
//                }
//                , error: function () {
//                    //演示失败状态，并实现重传
//                    var demoText = $('#demoText');
//                    demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
//                    demoText.find('.demo-reload').on('click', function () {
//                        uploadInst.upload();
//                    });
//                }
//            });
//        }
    });

    //城际联动
    var SCOPE = {
        "city_url": "{:url('admin/Advertuser/getCity')}",
    };

</script>
<script>
    $("#tel1").change(function(){
        var ret = /^1[34578]\d{9}$/;
        var telnum = $("#tel1").val();
       if (ret.test(telnum)) {
       } else {
           alert('请输入正确的手机号码');
           $("#tel1").val("");
       }
    });

    $("#tel2").change(function(){
        var ret = /^1[34578]\d{9}$/;
        var telnum = $("#tel2").val();
        if (ret.test(telnum)) {
        } else {
            alert('请输入正确的手机号码');
            $("#tel2").val("");
        }
    });

    $("#tel3").change(function(){
        var ret = /^1[34578]\d{9}$/;
        var telnum = $("#tel3").val();
        if (ret.test(telnum)) {
        } else {
            alert('请输入正确的手机号码');
            $("#tel3").val("");
        }
    });


    $("#idcard1").change(function(){
        var ret =  /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
        var idcard = $("#idcard1").val();
        if (ret.test(idcard)) {
        } else {
            alert('请输入正确的身份证号码');
            $("#idcard1").val("");
        }
    });

    $("#idcard2").change(function(){
        var ret =  /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
        var idcard = $("#idcard2").val();
        if (ret.test(idcard)) {
        } else {
            alert('请输入正确的身份证号码');
            $("#idcard2").val("");
        }
    });
</script>